/***************************************************************
Made by: Cultured::Labs

Copyright (c) 2010 Cultured::Labs
****************************************************************/
/////////////////////////////////////////////////////////////////
//Description:                                                 //
//A rock-paper-scissors game against the pc                    //
/////////////////////////////////////////////////////////////////
#include <iostream>
#include "randomOption.h"
#include "whoWins.h"
using namespace std;

int main() {
  const int WINSCORE = 3;
  char option_player, option_pc;
  int score_player = 0;
  int score_pc = 0;
  int winner;

  //game loop
  do {
    //user input
    cout << "Enter your choice (r=rock, p=paper, s=scissors)";
    cin >> option_player;

    //gets random pc option
    option_pc = randomOption();
    cout << "\nYou say: " << option_player << endl;
    cout << "I say: " << option_pc << endl;

    //checks the winner (0=tie, 1=1st ,2=2nd, -1=Error)
    winner = whoWins(option_player, option_pc);

    //result output
    cout << endl;
    if (winner == 0) {cout << ">>>Tied<<<\n";}
    else if (winner == 1) {
      cout << ">>>You win!<<<\n";
      score_player++;
    }
    else if (winner == 2) {
      cout << ">>>PC wins!<<<\n";
      score_pc++;
    } else {
      cout << "Please enter a valid option.\n";
    }

    //shows current scoreboard
    cout << endl << "POINTS: You: " << score_player;
    cout << "  PC: " << score_pc << endl << endl << endl;
  } while (score_player < WINSCORE && score_pc < WINSCORE);

  if (score_player > score_pc) {
    cout << ">>>>You win the competition!<<<<\n";
  } else {
    cout << ">>>>PC wins the competition!<<<<\n";
  }
}
